<?php

namespace Home\Controller;
use Think\Controller;


class HomeController extends Controller {
    
    public function __construct(){
        parent::__construct();
        if(!session('phone')){
            $this->redirect('/Home/Index/login');
        }
    }
    
    public function judgeParent(){
        if(session('type') != 2){
            $this->returnJs('Hey, you are not a parent');
        }else{
            return true;
        }
    }
    
    public function judgeRequirementDel($id, $user_id, $model){
        
        if($this->judgeParent()){
            $data = $model->where(array('id' => $id, 'user_id' => $user_id, 'status' => 0))->find();        
            if(!$data){
                $this->returnJs('Hey, you have no permission to do this!');
            }else{
                return $data;
            }
        }   
        
    }
    
    public function returnJs($str){
        echo "<script language='javascript'> 
        alert('".$str."'); 
        window.history.back(-1); 
        </script> ";
    }




    /**
     * 手机动态码
     * @param type $param
     */
    public function generate_phone_random($len)
    {
        $arrray = range(0, 9);
        $random = '';
        for ($i = 0; $i < $len; $i++) {
            $random .= $arrray[mt_rand(0, 9)];
        }
        return $random;
    }
    
    
    
}